package HTTPRecieveParser;

import HTTPSendIntegrator.MmsMessageException;

public class AcknowledgeInd {
	private String acknowledgeIndMessage;
	
	public static final String MMS_MESSAGE_TYPE = "X-Mms-Message-Type";
	public static final String MMS_TRANSACTION_ID = "X-Mms-Transaction-ID";
	public static final String MMS_VERSION = "X-Mms-MMS-Version";
	public static final String MMS_REPORT_ALLOWED = "X-Mms-Report-Allowed";
	
	private String mmsMessageType;
	private String mmsTransactionId;
	private String mmsVersion;
	private Boolean mmsReportAllowed;

	public String getMessageType(){
		return mmsMessageType;
	}
	
	public String getTransactionId(){
		return mmsTransactionId;
	}
	
	public String getVersion(){
		return mmsVersion;
	}

	public Boolean getReportAllowed(){
		return mmsReportAllowed;
	}

	public AcknowledgeInd(String acknowledgeIndMessage){
		this.acknowledgeIndMessage = acknowledgeIndMessage;
	}
	
	public void decodeMessage() throws MmsMessageException  {
	
		try{
			String[] result = acknowledgeIndMessage.split("\n");
		
			for(int i=0 ;i<result.length; i++)
			{
					if(result[i].startsWith(MMS_MESSAGE_TYPE))
						mmsMessageType=(result[i].substring((result[i].indexOf(':'))+2));
					
					if(result[i].startsWith(MMS_TRANSACTION_ID))
						mmsTransactionId=result[i].substring((result[i].indexOf(':'))+2); 
					
					if(result[i].startsWith(MMS_VERSION))
						mmsVersion=result[i].substring((result[i].indexOf(':'))+2);
					
					if(result[i].startsWith(MMS_REPORT_ALLOWED))
					{
						if(result[i].substring((result[i].indexOf(':'))+2) == "yes")
							mmsReportAllowed=true;
						else if(result[i].substring((result[i].indexOf(':'))+2) == "no")
							mmsReportAllowed=false;
					}
						
			}
		}catch (ArrayIndexOutOfBoundsException e){
			System.out.println("Malformed response message");
		}
	}
}
